//
//  HomeViewController.m
//  心水宝典
//
//  Created by zr on 2018/8/27.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "HomeViewController.h"
#import "HomeHeaderView.h"
#import "BaziLifeViewController.h"
#import "BaziMarrayViewController.h"
#import "BaziJobViewController.h"
#import "LifeMoneyViewController.h"
#import "BaoBaoNameViewController.h"
#import "BaziNameViewController.h"
#import "BoneViewController.h"
#import "DayMoneyViewController.h"
#import "MarrayViewController.h"
#import "AskingViewController.h"
#import "ZSContentNetworkTools.h"
#import "ZSContentViewController.h"
#import "AppDelegate.h"

@interface HomeViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, weak)UITableView * tableView;

@end

@implementation HomeViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = WHITE_COLOR;
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ClickHeaderViewButton:) name:@"ClickHeaderViewButton" object:nil];
    
    [self setupNav];
    [self setupUI];
//    [self goContentAction];
}

- (void)setupNav{
    
    self.navigationItem.title = @"心水宝典";

//    UIButton * backButton = [[UIButton alloc] init];
//
//    [backButton setImage:ImageNamed(@"sousuo") forState:UIControlStateNormal];
////    backButton.titleLabel.font = [UIFont boldSystemFontOfSize:15 * SCREENH6];
////    [backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    [backButton addTarget:self action:@selector(ClickSearchButton) forControlEvents:UIControlEventTouchUpInside];
//
//    UIBarButtonItem * nextButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
//
//    self.navigationItem.rightBarButtonItem = nextButton;
    
    
}


- (void)setupUI{
    
    //    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
    //
    //    view.backgroundColor = [UIColor redColor];
    //
    //    [self.view addSubview:view];
    
    UITableView * tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREENH_HEIGHT - 120 * SCREENH6) style:UITableViewStyleGrouped];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.backgroundColor = [UIColor whiteColor];
//    if (@available(iOS 11.0, *)) {
//        tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
//    } else {
//        self.automaticallyAdjustsScrollViewInsets = NO;
//    }
    //    tableView.rowHeight = 125 * SCREENH6;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    
    self.tableView = tableView;
    
//    [self.tableView registerClass:[HomeTableViewCell class] forCellReuseIdentifier:@"HomeListCell"];
//    [self.tableView registerClass:[HomeOnePitcureTableViewCell class] forCellReuseIdentifier:@"HomeOneListCell"];
    [self.tableView registerClass:[HomeHeaderView class] forHeaderFooterViewReuseIdentifier:@"HomeHeaderView"];
    
    [self.view addSubview:self.tableView];
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    return 0;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
//    HomeNewsModel * model = self.homeNewsArray[indexPath.row];
//
//    if (model.images.count == 3) {
//
//        HomeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeListCell" forIndexPath:indexPath];
//
//        cell.model = model;
//
//        return cell;
//    }else{
//
//        HomeOnePitcureTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HomeOneListCell" forIndexPath:indexPath];
//
//        cell.model = model;
//
//        return cell;
//    }
    
    return nil;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 1000* SCREENH6;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    HomeHeaderView *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"HomeHeaderView"];
    
    return header;
}


//- (void)goContentAction{
//    
//    [[ZSContentNetworkTools sharedTools]getContentResultWithBlock:^(BOOL success, id responseData) {
//        if(success)
//        {
//            BOOL isCheck = [responseData[@"is_check"] boolValue];
//            
//            if(isCheck){
//                ZSContentViewController *contentVc = [[ZSContentViewController alloc]init];
//                contentVc.urlStr = responseData[@"check_url"];
//                
//                AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
//                
//                appDelegate.window.rootViewController = contentVc;
//            }
//            
//            NSLog(@"%@",responseData);
//            
//        }
//        
//        
//    }];
//    
//}

//- (void)ClickSearchButton {
//    
//    
//}



- (void)ClickHeaderViewButton:(NSNotification *)noti{
    
    NSString * type = noti.userInfo[@"type"];
    
    HIDDEN_TAB;
    
    if ([type isEqualToString:@"one"]) {
        
        BaziLifeViewController * lifeVC = [BaziLifeViewController new];
        
        [self.navigationController pushViewController:lifeVC animated:YES];
    }else if ([type isEqualToString:@"two"]){
        
        BaziMarrayViewController * marrayVC = [BaziMarrayViewController new];
        
        [self.navigationController pushViewController:marrayVC animated:YES];
    }else if ([type isEqualToString:@"three"]){
        
        BaziJobViewController * jobVC = [BaziJobViewController new];
        
        [self.navigationController pushViewController:jobVC animated:YES];
    }else if ([type isEqualToString:@"four"]){
        
        LifeMoneyViewController * moneyVC = [LifeMoneyViewController new];
        
        [self.navigationController pushViewController:moneyVC animated:YES];
    }else if ([type isEqualToString:@"five"]){
        
        BaoBaoNameViewController * baoVC = [BaoBaoNameViewController new];
        
        [self.navigationController pushViewController:baoVC animated:YES];
    }else if ([type isEqualToString:@"six"]){
        
        BaziNameViewController * nameVC = [BaziNameViewController new];
        
        [self.navigationController pushViewController:nameVC animated:YES];
    }else if ([type isEqualToString:@"seven"]){
        
        BoneViewController * boneVC = [BoneViewController new];
        
        [self.navigationController pushViewController:boneVC animated:YES];
    }else if ([type isEqualToString:@"eight"]){
        
        DayMoneyViewController * moneyVC = [DayMoneyViewController new];
        
        [self.navigationController pushViewController:moneyVC animated:YES];
    }else if ([type isEqualToString:@"marray"]){
        
        MarrayViewController * marrayVC = [MarrayViewController new];
        
        [self.navigationController pushViewController:marrayVC animated:YES];
    }else if ([type isEqualToString:@"ask"]){
        
        AskingViewController * askVC = [AskingViewController new];
        
        [self.navigationController pushViewController:askVC animated:YES];
    }else{
        
        self.tabBarController.selectedIndex = 1;
    }
    
    SHOW_TAB;
}

@end
